package com.unit6.lq.util;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author 李琦 on 2021/8/20.
 * @version java version "16.0.1" 2021-04-20
 */
public class GetConnection {
//    private static Connection conn=null;//注册方法时多次使用同一个对象
    private static String url = "jdbc:mysql://localhost:3306/data2?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8";
    //useUnicode=true&characterEncoding=UTF-8";

    private static String dataBaseName="root";
    private static String dataBasePwd="123456";
    public static Connection getConn(){
        Connection conn=null;//每次获取到的Connection对象都是新的对象
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");//加载jdbc驱动
            conn= DriverManager.getConnection(url,dataBaseName,dataBasePwd);//连接数据库
            System.out.println("biu~");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("boom!");
        }
        return conn;
    }

}
